<!DOCTYPE html>
<html>
<head>
    <title>文档选择</title>
    <link rel="stylesheet" type="text/css" href="<?=base_url('public/css/common.css')?>"/>
    <link rel="stylesheet" type="text/css" href="<?=base_url('public/css/main.css')?>"/>
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="<?=base_url('public/lib/jqusey.form.js')?>"></script>
    <script type="text/javascript" src="<?=base_url('public/lib/layer/layer.js')?>"></script>
    <style type="text/css">
        table{border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;}
        th,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}
        th{font-weight:bold;background:#ccc;}
    </style>
</head>
<body>
<div style="margin: 20px">
    <form action="<?=site_url('article/choice')?>" method="post" id="myform">
        <input class="common-text" name="author" size="50" value="" type="text" placeholder="请输入文档标题或者ID号">
        <input type="submit" href="javascript:;" class="btn btn-primary mr10" value="搜索">
    </form>
</div>

<div style="margin-left: 10px">
    <table align="center" width="98%" style="margin-top: 10px">
        <tbody id="content">
            <tr style="background:#ddd" id="apped">
                <td>编号</td>
                <td width="40%">文档标题</td>
                <td>点击量</td>
                <td>更新时间</td>
                <td>选择</td>
            </tr>

        </tbody>

    </table>
</div>
<script type="text/javascript">
    $('#myform').submit(function() {
        var index = layer.load(2);
        $(this).ajaxSubmit(function(data){
            layer.close(index);
            $(".del").remove();
            data = JSON.parse(data);
            var l = '';
            $(data).each(function(index, el) {
                l += "<tr class='del'>";
                l += "<td>"+el.id+"</td>";
                l += "<td class='aid_"+el.id+"'>"+el.title+"</td>";
                l += "<td>"+el.click+"</td>";
                l += "<td>"+el.date+"</td>";
                l += "<td><a href='javascript:;' onclick='set_parent("+el.id+")'>选择该文档</a></td>";
                l += "</tr>";
            });
            if(!l){
                l = "<tr class='del'><td colspan='5' align='center'>没有找到相关记录</td></tr>"
            }
            $("#content").append(l);
        })
        return false;
    })

    function set_parent(id){
        //更改父级页面值
        var index = parent.layer.getFrameIndex(window.name);
        var title = $(".aid_"+id).html();
        parent.$('input[name=article_title]').val(title);
        parent.$('input[name=article_id]').val(id);
        parent.layer.close(index);
    }
</script>
</body>
</html>